
package nccloud.impl.arap.txdj.action;

import nc.bs.pub.action.N_TXDJ_UNSAVE;
import nc.impl.pubapp.pattern.data.bill.BillQuery;
import nc.impl.pubapp.pattern.rule.IRule;
import nc.impl.pubapp.pattern.rule.processer.AroundProcesser;
import nc.vo.arap.amortization.AggAmortizationVO;
import nc.vo.ml.NCLangRes4VoTransl;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nccloud.bs.arap.txdj.maintain.rule.unsave.CheckEnableSendApproveRule;
import nccloud.bs.arap.txdj.maintain.rule.unsave.SetFreeStateRule;
import nccloud.bs.arap.txdj.maintain.rule.unsave.UnSaveRule;
import nccloud.bs.arap.txdj.plugin.ActionPlugInPoint;

public class CallBackAction {
        public Object returnBill(N_TXDJ_UNSAVE script) {
                AggAmortizationVO[] vos = null;

                try {
                        Object[] obj = script.getPfParameterVO().m_preValueVos;
                        int len = obj.length;
                        if (0 == len) {
                                ExceptionUtils.wrappBusinessException(
                                                NCLangRes4VoTransl.getNCLangRes().getStrByID("4009001_0", "04009001-0046"));
                        }

                        vos = new AggAmortizationVO[len];

                        for (int i = 0; i < len; ++i) {
                                vos[i] = (AggAmortizationVO) obj[i];
                        }

                        AroundProcesser<AggAmortizationVO> processer = new AroundProcesser(ActionPlugInPoint.CallBackAction);
                        this.addBeforeRule(processer);
                        this.addAfterRule(processer);
                        processer.before(vos);
                        script.procRecallFlow(script.getPfParameterVO());
                        processer.after(vos);
                } catch (Exception var6) {
                        ExceptionUtils.wrappException(var6);
                }

                return this.queryNewVO(vos);
        }

        private void addAfterRule(AroundProcesser<AggAmortizationVO> processer) {
                 IRule<AggAmortizationVO> rule = new SetFreeStateRule();
                 processer.addAfterRule(rule);
        }

        private void addBeforeRule(AroundProcesser<AggAmortizationVO> processer) {
                 IRule<AggAmortizationVO> rule = new CheckEnableSendApproveRule();
                 processer.addBeforeRule(rule);
                 rule = new UnSaveRule();
                 processer.addBeforeRule(rule);
        }

        private AggAmortizationVO[] queryNewVO(AggAmortizationVO[] vos) {
                int len = vos.length;
                String[] pks = new String[len];

                for (int i = 0; i < len; ++i) {
                        pks[i] = vos[i].getPrimaryKey();
                }

                BillQuery<AggAmortizationVO> query = new BillQuery(AggAmortizationVO.class);
                AggAmortizationVO[] bills = (AggAmortizationVO[]) query.query(pks);
                return bills;
        }
}
